//
//  PersonalChangePassWordController.m
//  ChatForHot
//
//  Created by wr on 2018/10/17.
//  Copyright © 2018年 FLY. All rights reserved.
//

#import "PersonalChangePassWordController.h"
#import "PersonalSettingPassWordView.h"
#import "PersonalSettingViewModel.h"

@interface PersonalChangePassWordController ()<SettingChangeCodeDelegate>

@property (nonatomic, strong) PersonalSettingPassWordView *HOTCHATchangeView;
@property (nonatomic, strong) PersonalSettingViewModel *viewModel;
@end

@implementation PersonalChangePassWordController

- (void)HOTCHATdidInitialized {
    [super HOTCHATdidInitialized];
    
    self.viewModel = [[PersonalSettingViewModel alloc] init];
}

- (void)HOTCHATInsertSubViews {
    [super HOTCHATInsertSubViews];
    
    self.HOTCHATchangeView = [[PersonalSettingPassWordView alloc] init];
    self.HOTCHATchangeView.delegate = self;
    [self.view addSubview:self.HOTCHATchangeView];
}

- (void)HOTCHATsetNavigationItemsIsInEditMode:(BOOL)isInEditMode animated:(BOOL)animated {
    [super HOTCHATsetNavigationItemsIsInEditMode:isInEditMode animated:animated];
    
    self.title = NSLocalizedString(@"personS1", nil);
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    @weakify(self)
    [self.viewModel.requestChangePassWordCommand.executionSignals subscribeNext:^(RACSignal *excution) {
        [[excution dematerialize] subscribeNext:^(id x) {
            @strongify(self)
            [self HOTCHATshowMessage:NSLocalizedString(@"personS13", nil)];
            [self.navigationController popViewControllerAnimated:YES];
        } error:^(NSError *error) {
        }];
    }];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    [self.HOTCHATchangeView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
}

- (void)HOTCHATchangeCode:(NSString *)firstStr confirmStr:(NSString *)confirmStr {
    if (firstStr.length == 0 || confirmStr.length == 0) {
        [self HOTCHATshowMessage:NSLocalizedString(@"personS9", nil)];
        return;
    }
    if (![firstStr isEqualToString:confirmStr]) {
        [self HOTCHATshowMessage:NSLocalizedString(@"personS10", nil)];
        return;
    }
    if (firstStr.length < 6) {
        [self HOTCHATshowMessage:NSLocalizedString(@"personS11", nil)];
        return;
    }
    if (firstStr.length > 20) {
        [self HOTCHATshowMessage:NSLocalizedString(@"personS12", nil)];
        return;
    }
    [self.viewModel.requestChangePassWordCommand execute:confirmStr];
}

@end
